package com.cande.loki.test;

/**
 * @Description TODO
 * @Author wgf
 * @Date 2024/12/16 5:37 PM
 */
import java.util.*;
import java.util.stream.Collectors;
public class User {


        private int activityId;
        private int order;
        private String name;

        public User(int activityId, int order, String name) {
            this.activityId = activityId;
            this.order = order;
            this.name = name;
        }

        public int getActivityId() {
            return activityId;
        }

        public int getOrder() {
            return order;
        }

        public String getName() {
            return name;
        }

        @Override
        public String toString() {
            return "User{" +
                    "activityId=" + activityId +
                    ", order=" + order +
                    ", name='" + name + '\'' +
                    '}';
        }

        public static void main(String[] args) {

           User user = new User(1, 5, "Alice");
           User user1 = new User(1, 5, "Alice");
            System.out.println(user.equals(user1));

            // 初始化用户列表
            List<User> users = Arrays.asList(
                    new User(1, 5, "Alice"),
                    new User(1, 10, "Bob"),
                    new User(2, 7, "Charlie"),
                    new User(2, 3, "David"),
                    new User(3, 15, "Eve")
            );

            // 根据 activityId 聚合，并取 order 最大的对象
            List<User> result = users.stream()
                    .collect(Collectors.groupingBy(User::getActivityId))
                    .values()
                    .stream()
                    .map(group -> group.stream()
                            .max(Comparator.comparingInt(User::getOrder))
                            .orElse(null)) // 处理可能为空的情况
                    .filter(Objects::nonNull)
                    .collect(Collectors.toList());

            // 打印结果
            result.forEach(System.out::println);
        }

}
